package top.ffhome.system.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import top.ffhome.common.core.mybatisplus.service.impl.BaseServiceImpl;
import top.ffhome.system.domain.SysPost;
import top.ffhome.system.mapper.SysPostMapper;
import top.ffhome.system.service.ISysPostService;

import java.util.List;

/**
 * 岗位信息 服务层处理
 *
 * @author ruoyi
 */
@Service
public class SysPostServiceImpl extends BaseServiceImpl<SysPostMapper, SysPost> implements ISysPostService {
    @Override
    protected QueryWrapper<SysPost> generateWrapper(SysPost query) {
        return new QueryWrapper<SysPost>()
                .like(StrUtil.isNotBlank(query.getPostCode()), "post_code", query.getPostCode())
                .like(StrUtil.isNotBlank(query.getPostName()), "post_name", query.getPostName())
                .eq(StrUtil.isNotBlank(query.getStatus()), "status", query.getStatus());
    }

    @Override
    public List<SysPost> selectAll() {
        return selectList(new QueryWrapper<SysPost>().orderByAsc("post_sort"));
    }

    @Override
    public List<Long> selectListByUserId(Long userId) {
        return mapper.selectListByUserId(userId);
    }

    @Override
    public boolean checkPostNameExists(SysPost post) {
        return mapper.exists(new QueryWrapper<SysPost>().eq("post_name", post.getPostName())
                .ne(ObjectUtil.isNotNull(post.getPostId()), "post_id", post.getPostId()));
    }

    @Override
    public boolean checkPostCodeExists(SysPost post) {
        return mapper.exists(new QueryWrapper<SysPost>().eq("post_code", post.getPostCode())
                .ne(ObjectUtil.isNotNull(post.getPostId()), "post_id", post.getPostId()));
    }
}
